package pl.koziolekweb.prusakolep;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

import pl.koziolekweb.prusakolep.controllers.BasicActionController;
import pl.koziolekweb.prusakolep.controllers.BugListActionController;
import pl.koziolekweb.prusakolep.controllers.ConsoleDispatcher;
import pl.koziolekweb.prusakolep.controllers.Controller;
import pl.koziolekweb.prusakolep.controllers.ExitActionController;
import pl.koziolekweb.prusakolep.controllers.NewBugActionController;
import pl.koziolekweb.prusakolep.controllers.WelcomeController;

/**
 * 
 * @author bartlomiejk
 * 
 * 
 *         $Id: App.java 119 2009-02-17 22:36:34Z bjkuczynski $
 */
public class App {
	public static final String PATH = "./bugs";
	private static ConsoleDispatcher dispatcher;

	private static HashMap<String, Object> obj = new HashMap<String, Object>();

	public static void main(String[] args) {
		File db = new File(PATH);
		dispatcher = prepareDispatcher();
		if (!db.exists()) {
			db.mkdir();
		}
		dispatcher.dispatch("Welcome", null);
		obj.put("Dispatch", dispatcher);
		while (true) {
			dispatcher.dispatch("Basic", obj);
		}
	}

	private static ConsoleDispatcher prepareDispatcher() {
		Map<String, Controller> mapping = new HashMap<String, Controller>();
		mapping.put("Welcome", new WelcomeController());
		mapping.put("Basic", new BasicActionController());
		mapping.put("Exit", new ExitActionController());
		mapping.put("BugList", new BugListActionController());
		mapping.put("NewBug", new NewBugActionController());
		return new ConsoleDispatcher(mapping);
	}
}
